module HazardDetectorBranch (
    input [4:0]  rs,
    input [4:0]  rt,
    input [1:0]  Branch,
    input        id_ex_MemRead,
    input [4:0]  id_ex_des_reg,
    input        ex_mem_MemRead,
    input [4:0]  ex_mem_des_reg,
    input rst,
    output reg stall
);
    parameter   RD2 = 1'b1, IMMEDIATE_NUMBER = 1'b0;            // AluSrc
    always @(posedge rst) begin
        stall = 1'b0;
    end
    always @(*) 
    begin
        if(Branch)
        begin
                if(id_ex_MemRead&&(rs==id_ex_des_reg||rt==id_ex_des_reg))
                begin
                    stall = 1'b1;
                end
                else if(ex_mem_MemRead&&(rs==ex_mem_des_reg||rt==ex_mem_des_reg))
                    stall = 1'b1;
                else 
                begin
                    stall = 1'b0;
                end
        end
    end
endmodule //hazard

mmodule HazardDetectorAlu (
    input [4:0]  id_ex_rs,
    input [4:0]  id_ex_rt,
    input        ex_mem_MemRead,
    input [4:0]  ex_mem_des_reg,
    input        id_ex_AluSrc,
    input rst,
    output reg stall
);
    parameter   RD2 = 1'b1, IMMEDIATE_NUMBER = 1'b0;            // AluSrc
    always @(posedge rst) begin
        stall = 1'b0;
    end
    always @(*) begin
        if(ex_mem_MemRead&&(id_ex_rs==ex_mem_des_reg||(id_ex_rt==ex_mem_des_reg&&id_ex_AluSrc==RD2)))
        begin
            stall = 1'b1;
        end
        else 
        begin
            stall = 1'b0;
        end
    end
endmodule //hazard

//HazardDetectorAlu hazard_detector_alu(reg_id_ex_instr_out[25:21],reg_id_ex_instr_out[20:16],reg_ex_mem_MemRead_out,reg_ex_mem_des_reg_out,reg_id_ex_AluSrc_out,rst,hazard_detector_branch_stall_out);